//Accepted
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;


int g, p, s, k, i, j, x;
char a[100][100];
pair<int,int> tot[100];

int main (){
	//freopen("in.txt", "r", stdin);
	scanf("%d%d", &g, &p);
	while(g&&p){
		memset(a,0,sizeof(a));
		for(i=0;i<g;++i)
			for(j=0;j<p;++j){
				scanf("%d", &x);
				a[j][x-1]++;
			}
		scanf("%d", &s);
		while(s--){
			scanf("%d", &k);
			for(j=0;j<p;++j)tot[j].first=0;
			
			for(j=0;j<k;++j){
				scanf("%d", &x);
				for(i=0;i<p;++i){
					if(a[i][j]){
						tot[i].first-=x*a[i][j];
						tot[i].second=i+1;
						//printf("esse cara %d, acaba de ganhar %d de pontos=%d||%d\n", i,x, tot[i].first, tot[i].second);
					}
				}
			}
			sort(tot,tot+p);
			printf("%d", tot[0].second );
			i=1;
			while(tot[i].first==tot[i-1].first)
				printf(" %d", tot[ i++ ].second );
			printf("\n");
		}
		scanf("%d%d", &g, &p);
	}
	return 0;
}
